package com.itlaoqi.thread;

import java.util.Random;

/**
 * 使用机继承Tread的方式实现多线程
 */
public class Match1 {

    public static void main(String[] args) {
        Runner liuxiang = new Runner();
        //设置线程名字
        liuxiang.setName("刘翔");
        liuxiang.start();

        Runner laoqi = new Runner();
        //设置线程名字
        laoqi.setName("老齐");
        laoqi.start();

        Runner lufei = new Runner();
        //设置线程名字
        lufei.setName("路飞");
        lufei.start();

    }
}
class Runner extends Thread{
    @Override
    public void run() {
        Integer speed = new Random().nextInt(100);
        for (int i = 0;i<100;i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //this.getName()打印当前线程的名字
            System.out.println(this.getName() + "以前进" + (i * speed) + "米（" + speed + "米/秒）");
        }
    }
}
